package com.zrrd.ajaxDemo;

import com.zrrd.javaWeb.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author WanJl
 * @version 1.0
 * @title registerAjaxServlet
 * @description
 * @create 2024/1/20 9:58
 */
@WebServlet("/queryByUsernameAjaxServlet")
public class QueryByUsernameAjaxServlet extends HttpServlet {
    private UserService userService=new UserService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //1、接收前端的请求，获取请求的用户名
        String username = req.getParameter("username");
        System.out.println(username);
        //2、调用service层的查询方法
        Boolean flag = userService.queryUserByUsername(username);
        System.out.println(flag);
        //3、响应标记
        resp.getWriter().write(Boolean.toString(flag));
        System.out.println("响应完成.....");

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
